using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using Domain.Provider;
using Domain.Context;
using WebUI.DataModel;
using Domain.Logging;

namespace WebUI.Controllers
{
    public class AccountController : NMCToolControllerBase
    {
        private IDataProvider<AccountType> _repository;

        public AccountController(LogService logger, IDataProvider<AccountType> repository) : base(logger)
        {
            _repository = repository;
        }

        public ActionResult Save(AccountType accountType)
        {
            try
            {
                _repository.SaveEntity(accountType, User);

                return PartialView("_AccountTypesGrid", _repository.Entities);
            }
            catch (Exception e)
            {
                LogException(this, e);
                return RedirectToAction("error", "DatabaseError");
            }
        }

        public ActionResult Delete(AccountType accountType)
        {
            try
            {
                _repository.DeleteEntity(accountType, User);

                return PartialView("_AccountTypesGrid", _repository.Entities);
            }
            catch (Exception e)
            {
                LogException(this, e);
                return RedirectToAction("error", "DatabaseError");
            }
        }

        public ActionResult AccountTypesGrid()
        {
            try
            {
                return PartialView("_AccountTypesGrid", _repository.Entities);
            }
            catch (Exception e)
            {
                LogException(this, e);
                return RedirectToAction("error", "DatabaseError");
            }
        }

        public ActionResult Index()
        {
            try
            {

                return View(_repository.Entities);
            }
            catch (Exception e)
            {
                LogException(this, e);
                return RedirectToAction("error", "DatabaseError");
            }
        }
    }
}